﻿using System;
using System.Collections;
using System.Web;
using System.Web.Caching;

namespace MvcForum.Net.Business.Utils
{
    public class CacheWaper
    {

        public static object Get(string _key)
        {
            return HttpContext.Current.Cache[_key];

        }
        public static object Remove(string _key)
        {
            return HttpContext.Current.Cache.Remove(_key);

        }

        public static void Add(string _key, object _value, double _seconds)
        {
            if (_seconds > 0)
                HttpContext.Current.Cache.Insert(_key, _value, null, DateTime.Now.AddSeconds(_seconds), TimeSpan.Zero);
        }

        public static void Add(string _key, object _value, CacheDependency _dep)
        {

            HttpRuntime.Cache.Insert(_key, _value, _dep, DateTime.MaxValue, TimeSpan.Zero);

        }


        public static void Add(string _key, object _value)
        {   
            Add(_key, _value, 1200);
        }

        #region Clear Cache

        public static void Clear()
        {

            IDictionaryEnumerator _ie = HttpContext.Current.Cache.GetEnumerator();
            while (_ie.MoveNext())
            {
                HttpContext.Current.Cache.Remove(_ie.Key.ToString());
            }

        }

        #endregion
    }
}
